package com.example.replacebooks.controller;

import com.example.replacebooks.common.Result;
import com.example.replacebooks.entity.Address;
import com.example.replacebooks.entity.Class;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.service.AddressService;
import com.example.replacebooks.service.ClassService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/address")
public class AddressController {

    private static final Logger log = LoggerFactory.getLogger(AddressController.class);

    @Resource
    private AddressService addressService;

    @GetMapping
    public Result findAll(){return Result.success(addressService.findAll());}

    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Address> info = addressService.findBySearch(params);
        return Result.success(info);
    }
    @GetMapping("/findbyid")
    public Result findById(Params params){
        PageInfo<Address> info = addressService.findById(params);
        return Result.success(info);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Address address){
        addressService.add(address);
        return Result.success();
    }

    @DeleteMapping("/{addressid}")
    public Result delete(@PathVariable Integer addressid){
        addressService.delete(addressid);
        return Result.success();
    }
}
